package cn.batch.daemon.hibernate.dao;

// Generated 2012-10-29 14:03:03 by Hibernate Tools 3.4.0.CR1

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.batch.daemon.bean.ApplicantionInfo;

/**
 * Home object for domain model class PbocSummary.
 * 
 * @see cn.batch.daemon.hibernate.bean.PbocSummary
 * @author Hibernate Tools
 */
public class ApplicationInfoDao extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ApplicationInfoDao.class);

	protected void initDao() {
		// do nothing
	}

	public void save(ApplicantionInfo transientInstance) {
		log.debug("saving PbocSummary instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void saveAll(List<ApplicantionInfo> appInfoCache) {
		getHibernateTemplate().saveOrUpdateAll(appInfoCache);
	}
	
	public List<ApplicantionInfo> queryByExample(ApplicantionInfo transientInstance) {
		try {
			@SuppressWarnings("unchecked")
			List<ApplicantionInfo> list = getHibernateTemplate().findByExample(transientInstance);
			return list;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	public void delete(ApplicantionInfo transientInstance) {
		log.debug("delete ApplicantionInfo instance");
		try {
			getHibernateTemplate().delete(transientInstance);	
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
					
	}
	
	public void deleteAll(List<ApplicantionInfo> entities) {
		getHibernateTemplate().deleteAll(entities);
	}

	public void deleteAppInfoByBatchNoAndType(final String batchDate,
			final String value) {
		/*
		 * getHibernateTemplate().execute(new HibernateCallback() {
		 * 
		 * @Override public Object doInHibernate(Session session) throws
		 * HibernateException, SQLException { session.createQuery(
		 * "delete ApplicantionInfo where batchNo = :batchDate and batchType = :value"
		 * ) .setString("batchDate", batchDate) .setString("value",
		 * value).executeUpdate(); return null; } });
		 */
		String sql = " delete from APPLICANTION_INFO  where BATCH_NO = '"
				+ batchDate + "' and batch_type = '" + value + "'";
		Session session = getSessionFactory().getCurrentSession();
		Query query = session.createSQLQuery(sql);
		query.executeUpdate();
	}

	
}
